package cn.gson.crm.controller.employee;

import cn.gson.crm.controller.BaseServlet;
import cn.gson.crm.model.dao.EmpDao;
import cn.gson.crm.model.entity.Dept;
import cn.gson.crm.model.entity.Employee;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;

/**
 * 处理页面上重置密码的ajax
 */
@WebServlet("/employee/changepasswordajax")
public class EmployeeChangePasswordAjaxServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
	private EmpDao empDao=new EmpDao();

	protected void get(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String id=request.getParameter("id");
		Employee employee=empDao.getUserById(id);
		employee.setEmpPassword("1");
		boolean result=empDao.updateEmp(employee, id);
		response.setContentType("application/json;charset=utf-8");

		// 把结果转换成JSON字符串
		String jsonStr = JSONArray.toJSONString(result);
		System.out.println(jsonStr);
		// 输出结果
		response.getWriter().append(jsonStr);
	}

}
